<include file="Common:header" />
<TYimport plugin='datepicker' />
<div class="table_content" >
    <form enctype="multipart/form-data" id="upForm" class="ajax_form">
        <table class="edit_table">
            <tr>
                <td class="tablehead">用戶名：</td>
                <td>
                    <input type="text" name="name" class="text w150 required" value="{$info.name}" style="width:200px;"/><label class="tips"></label>
                </td>
            </tr>
             <tr>
                <td class="tablehead">店鋪地址：</td>
                <td>
                    <input type="text" name="address" class="text w150 required" value="{$info.address}" style="width:200px;"/><label class="tips"></label>
                </td>
            </tr>
            <if condition="$address neq no">
            <foreach name="address" item="vo" key="k">
            <tr>
                <td class="tablehead">洗車地址{$k+1}：</td>
                <td>
                    <input type="text" name="address_name[]" class="text w150 required" value="{$vo.address_name}" style="width:300px;"/><label class="tips"></label>
                	<img src="__PRIVATE__/images/删除.png" class="delete_address" title="删除地址"><input type="hidden" name='delete_address' addressId="{$vo.id}"/>
                	<if condition="!isset($address[$k+1])">
                		<img src="__PRIVATE__/images/添加.png" class="add_new_address" title="添加新地址">
                	</if>
                </td>
            </tr>
			</foreach>
			<else/>
			<tr>
                <td class="tablehead">洗車地址：</td>
                <td>
                    <input type="text" name="address_name[]" class="text w150 required" value="" style="width:300px;"/><label class="tips"></label>
                	<img src="__PRIVATE__/images/添加.png" class="add_new_address" title="添加新地址">
                </td>
            </tr>
			</if>
            <tr class="server_tel">
                <td class="tablehead">電話</td>
                <td>
                    <input type="text" name="phone" class="text w150 required" value="{$info.phone}"/><label class="tips"></label>
                </td>
            </tr>

			<tr>
                <td class="tablehead">圖片</td>
                <td>
                    <img src="{$info.shop_img}" id="shop_img" name="shop_img" style="width:200px;"/><br/>
                    
                    <input type="button" class="up" value="上傳新圖片" style="padding:10px;margin-top:10px;"/>
                    <input type="file" id="upload_shopImg" name="upload_shopImg"  onchange="showPicture(this)" style="display:none;"/>
                </td>
            </tr>
				
			<script type="text/javascript">
			$('.up').click(function(){
				$('#upload_shopImg').click();
			});
			function showPicture(imgFile){
				var picURL = window.URL.createObjectURL(imgFile.files[0]);
				document.getElementById("shop_img").src = picURL;
				$('#upload_shopImg').val(picURL);
			} 
			</script>

            <tr>
                <td class="tablehead">溫馨提示</td>
                <td>
                	<textarea class="shop_tips" name="tips" style="width:300px;height:200px;">
                		{$info.tips}
                	</textarea>
                	
                    <label class="tips"></label>
                </td>
            </tr>
            <tr>
                <td class="tablehead">操作</td>
                <td>
                	<input type="hidden" name="server_id" value="{$_GET['id']}"/>
                	<input type="button" class="save_btn" value="保存"/>
                    <input type="button" class="back_btn" value="返回"/>
                </td>
            </tr>
        </table>
    </form>
</div>
<script type="text/javascript">
$('.add_new_address').click(function(){
	var html = "<tr>";
		html += "<td class='tablehead'>新增地址：</td>";
		html += "<td>";
		html +=     "<input type='text' name='address_name[]' class='text w150 required' style='width:300px;'/>";
		html += "</td>";
		html += "</tr>";
	$('.server_tel').before(html);
});

$('.delete_address').click(function(){
	var addressId = $(this).next('input[name=delete_address]').attr('addressId');
	art.dialog({
        id: 'confirm',
        title: '消息',
        icon: 'question',
        opacity: .1,
        resize: false,
        lock: true,
        fixed: true,
        content: '你確定要刪除此地址？',
        button: [
            {
                name: '确定',
                callback: function() {
                    this.close();
                    
                	$.ajax({    
                        url: "{:U(MODULE_NAME.'/'.CONTROLLER_NAME.'/delete_address')}" ,  
                        type: 'POST',   
                        dataType: 'json',
                        data : {addressId : addressId},    
                        success: function (returndata) {    
                       		if(returndata.status){
                       			alert(returndata.info);
                       		 /* callBackTips(returndata.status,returndata.info); */
                       			window.location.href = window.location.href;
                    		}else{
                    			callBackTips(0,returndata.info);
                    		}
                        },    
                   }); 
                    return false;
                },
                focus: true
            },
            {
                name: '取消'
            }	
        ]
    });
	
});


$('.save_btn').click(function(){
	var formData = new FormData($( "#upForm" )[0]);   
    $.ajax({    
         url: "{:U(MODULE_NAME.'/'.CONTROLLER_NAME.'/save_new_shop_info')}" ,  /*这是处理文件上传的servlet*/  
         type: 'POST',    
         data : formData,    
         async: false,    
         cache: false,    
         contentType: false,    
         processData: false,    
         success: function (returndata) {    
        	if(returndata.status){
        		 callBackTips(returndata.status,returndata.info);
     		}else{
     			callBackTips(0,returndata.info);
     		}
         },    
    });    
});
</script>
<include file="Common:footer" />
